package com.boruiimage.demo.controller;

import com.boruiimage.demo.doMain.Result;
import com.boruiimage.demo.doMain.memberuser;
import com.boruiimage.demo.doMain.recharacterinfo;
import com.boruiimage.demo.doMain.results;
import com.boruiimage.demo.repository.registerMemberUserDao;
import com.boruiimage.demo.utils.AES;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class registerMemberUser {
    @Autowired
    registerMemberUserDao rmud;
    @RequestMapping("/addMemberUser")
    public Result add(@RequestBody Map<String,String>map){
        Result rs=new Result();
        int systemCount=0;
        int personCount=0;
        String payContext="";
        double payNum= Double.parseDouble(map.get("payNum"));
        int memberCode= java.lang.Integer.parseInt(map.get("memberCode"));
        if(memberCode==1){//金牌会员
            systemCount=200;
            personCount=5;
            payContext="开通金牌会员";
        }else if(memberCode==2){//银牌会员
            systemCount=100;
            personCount=1;
            payContext="开通银牌会员";
        }
        else if(memberCode==3){//铜牌会员
            systemCount=50;
            personCount=0;
            payContext="开通铜牌会员";
        }
        rs=rmud.addMemberUser(map.get("userName"),systemCount,personCount,null,memberCode);
        if(rs.getCode().equals(1)){
          rs=rmud.addRechargeInfo(map.get("userName"),payContext,payNum,map.get("rechargeContext"),null);
        }
        return rs;
    }
    @RequestMapping("/selectRechange")
    public results showRechange(@RequestParam("userName")String userName,@RequestParam(value = "pageIndex") Integer pageIndex){
        results re=new results();
        PageHelper.startPage(pageIndex,15);
        List<recharacterinfo> list=rmud.selByrecharacterinfo(AES.encrypt(userName));
        int count =rmud.selByrecharacterinfoCount(AES.encrypt(userName));
        re.setCount(count);
        re.setList(list);
        return re;
    }
    @RequestMapping("/selectVip")
    public results showVip(@RequestParam("userName")String userName,@RequestParam(value = "pageIndex") Integer pageIndex){
        results re=new results();
        PageHelper.startPage(pageIndex,15);
        List<memberuser> list=rmud.listMemberuserByPc(AES.encrypt(userName));
        int count =rmud.listMemberuserByPCount(AES.encrypt(userName));
        re.setCount(count);
        re.setList(list);
        return re;
    }

}
